﻿Ext.define('app.system.project_role.Edit',
{
    extend: 'Ext.window.Window',
    autoScroll: true,
    modal: true,
    width: 600,
    height: 400,
    layout: 'fit',
    recordData: undefined,
    bodyStyle: 'padding:10px',
    initComponent: function () {
        var me = this;
        me.items = [me.getRoleForm()];
        me.buttons = [
            {
                text: '保存', scope: this, handler: function () {
                    var values = me.getRoleForm().getValues();
                    App.AjaxPost('/api/services/app/projectRole/EditRole', values, function (data) {
                        me.fireEvent("savesuccess");
                    });
                }
            },
            { text: '关闭', handler: function () { me.close(); } }
        ]
        me.callParent();
    },
    listeners: {
        afterrender: function (me) {
            if (me.recordData) {
                me.getRoleForm().getForm().setValues(me.recordData.data);
            }
        }
    },
    getRoleForm: function () {
        var me = this;
        if (!this.roleform) {
            this.roleform = new Ext.form.Panel({
                border: false,
                defaults: {
                    anchor: '100%',
                    xtype: 'textfield',
                    labelAlign: "right"
                },
                items: [
                    {
                        xtype: 'hidden',
                        name: 'id',
                        value: 0
                    },
                    {
                        fieldLabel: '角色名称',
                        name: 'roleName'
                    },
                     {
                         fieldLabel: '顺序',
                         xtype: 'numberfield',
                         name: 'sortfactor'
                     },
                    {
                        xtype: 'textarea',
                        height: 200,
                        fieldLabel: '描述',
                        name: 'description'
                    }
                ]
            });
        }
        return this.roleform;
    }
});